from pathlib import Path
import shutil
import random
from string import ascii_lowercase

p = Path('a/b/c/d')
shutil.rmtree('a', ignore_errors=True)
p.mkdir(parents=True,exist_ok=True)
paths = (p,*p.parents)[:-1]
filenames = (''.join(random.choices(ascii_lowercase,k=4)) for i in range(50))
for file in filenames:
    (random.choices(paths)[0] / file).touch()
pre= tuple(_ for _ in 'abcdefghijklmnopqrstuvw')
shutil.rmtree('dst',ignore_errors=True)
def ignore(src, names):
    ig = filter(lambda x: x.startswith(pre) and (src / Path(x)).is_file() , names) # 忽略a开头的
    return set(ig)
shutil.copytree('a','dst',ignore=ignore, dirs_exist_ok=True)

